cmake_minimum_required(VERSION 3.10)
project(FlightServer)

set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)

# Qt 路径提示（使用你的 Qt 安装路径），建议也可在 CMake 配置时通过 -DCMAKE_PREFIX_PATH 传入
# 例如：-DCMAKE_PREFIX_PATH=E:/Qt/6.10.0/mingw_64/lib/cmake
set(CMAKE_PREFIX_PATH "E:/Qt/6.10.0/mingw_64/lib/cmake" CACHE PATH "Qt6 CMake prefix path")

# 查找 Qt6 组件（至少需要 Sql；Core；Network 用于邮件发送）
find_package(Qt6 REQUIRED COMPONENTS Sql Core Network)

# 源文件
set(SOURCES
        main.cpp
        src/config.cpp
        src/Server.cpp
        src/middleware.cpp
        src/route.cpp
        src/Threadpool.cpp
        src/util.cpp
        src/database.cpp
        src/redis.cpp
        src/emailSender.cpp
        src/jwt.cpp
        src/JsonValue.cpp
        headler/EmailHeadler.cpp
        headler/TicketsHeadler.cpp
        headler/UserHeadler.cpp
        headler/MaintainAdminHeadler.cpp
        src/Log.cpp
        headler/StationHeadler.cpp
        headler/MoneyAdminHeadler.cpp
        headler/ContentAdminHeadler.cpp
)

# 头文件
set(HEADERS
        include/Server.h
        include/middleware.h
        include/route.h
        include/Threadpool.h
        include/util.h
        include/config.h
        include/database.h
        include/redis.h
        include/emailSender.h
        include/Headler.h
        include/jwt.h
        include/JsonValue.h
        include/Log.h
)

set(MODELS
        model/User.cpp
        model/User.h
        model/Model.cpp
        model/Model.h
        model/Ticket.cpp
        model/Ticket.h
        model/Sale.cpp
        model/Sale.h
        model/Order.cpp
        model/Order.h
        model/TicketOperation.cpp
        model/TicketOperation.h
        model/Notification.cpp
        model/Notification.h
        model/Travel.cpp
        model/Travel.h
        model/Browse.cpp
        model/Browse.h
        model/Ask.cpp
        model/Ask.h
        include/Log.h
        model/Stations.cpp
        model/Stations.h
        model/StationsPoints.cpp
        model/StationsPoints.h
        model/Check.cpp
        model/Check.h
        model/Game.cpp
        model/Game.h
        model/Train.cpp
        model/Train.h
        model/StationTrain.cpp
        model/StationTrain.h
        model/Friend.cpp
        model/Friend.h
        model/AdminLog.cpp
        model/AdminLog.h
)

# 包含目录
include_directories(${CMAKE_SOURCE_DIR}/include)
include_directories("C:\\msys64\\usr\\local\\include")
link_directories("C:\\msys64\\usr\\local\\lib")
#include_directories("C:\\msys64\\mingw64\\include")
#link_directories("C:\\msys64\\mingw64\\lib")

# 创建可执行文件
add_executable(${PROJECT_NAME} ${SOURCES} ${HEADERS} ${MODELS})

# 链接库（Qt + Windows 套接字库 + hiredis）
target_link_libraries(${PROJECT_NAME} PRIVATE
        Qt6::Sql
        Qt6::Core
        Qt6::Network
        iphlpapi        # 补充网络库
        hiredis         # Redis 客户端库（先链接）
        ws2_32          # Windows 网络核心库（放在 hiredis 之后）
)

# 编译选项
if(MSVC)
    target_compile_options(${PROJECT_NAME} PRIVATE /W4)
else()
    target_compile_options(${PROJECT_NAME} PRIVATE -Wall -Wextra -g)
endif()

# 设置输出目录
set_target_properties(${PROJECT_NAME} PROPERTIES
    RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}
)